home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / utilz / unpcklbm / unp_lbm.m < prev   
Text File  |  1996-01-04  |  5KB  |  144 lines

  1. ;════════════════════════════════════════════════════════════════════════════
  2. ;UNPACK_LBM = routine depacks a 256color LBM-File an stores it into memory.
  3. ;
  4. ;             Version v3.1 done by Capella of Escape  
  5. ;             
  6. ;             This routine works in Protected-mode, so keep sure that you
  7. ;             have CS and DS set to one Huge 32bit segment...
  8. ;             This routine is freeware, so use it in any way you want!!
  9. ;             This routine don't takes care of the colortable, but give back
  10. ;             an offset to the colotable at the end of the routine, which can
  11. ;             be used to load the colortable with an own routine.
  12. ;             This code runs with each Pmode-Extender, so no needs to convert
  13. ;             it. I don't understand why so much people only uses PCX-files 
  14. ;             which are much longer than LBM-files.  
  15. ;
  16. ;IN:  ESI  = Offset to the Source-Datas              
  17. ;     ECX  = Filelength of loaded LBM-File
  18. ;     EDI  = Offset to the Target-Buffer
  19. ;
  20. ;OUT: Carry=0 then;
  21. ;                       AX  = Xsize of Picture
  22. ;                       BX  = Ysize of Picture
  23. ;                       ESI = Offset to the Colortable
  24. ;                       
  25. ;     Carry=1 then something went wrong...
  26. ;
  27. ;                       AX = error-code   / 01h = Colormap not found
  28. ;                                           02h = Bitmap not found 
  29. ;════════════════════════════════════════════════════════════════════════════
  30.  
  31. Color_Table     dd ?
  32. Bitmap_Table    dd ?
  33. LBM_Xsize       dw ?
  34. LBM_Ysize       dw ?
  35. Bitmap_Bytes    dd ?
  36.  
  37. unpack_lbm:     push esi
  38.                 push ecx
  39.  
  40.                 add esi,14h
  41.                 mov ax,ds:[esi+2]     ; get y-size of picture
  42.                 xchg al,ah            ; switch low/high coz of amiga-format
  43.                 mov ds:[LBM_Ysize],ax
  44.                 cwde                  ; convert AX to EAX with same value
  45.                 mov ebx,eax
  46.  
  47.                 mov ax,ds:[esi]       ; get x-size of picture
  48.                 xchg al,ah            ; switch low/high coz of amiga-format
  49.                 mov ds:[LBM_Xsize],ax
  50.                 cwde                  ; convert AX to EAX with same value
  51.                 
  52.                 imul ebx                   ; calculate real amount of bytes
  53.                 mov ds:[Bitmap_Bytes],eax  ; used in the bitmap
  54.                 
  55.                 mov ebx,"PAMC"        ; search for colortable
  56.  
  57. x1:             mov eax,ds:[esi]
  58.                 cmp eax,ebx
  59.                 je x2
  60.  
  61.                 inc esi
  62.                 dec ecx
  63.                 jnz x1
  64.                 
  65.                 pop ecx
  66.                 pop esi
  67.                 stc
  68.                 mov ax,01h
  69.                 ret
  70.  
  71. x2:             add esi,8
  72.                 mov ds:[Color_Table],esi  ; store offset to colortable
  73.                 pop ecx
  74.                 pop esi               ; searching for the Bitmap-data begins
  75.                                       ; at the beginning of the file, normaly
  76.                                       ; it's not needed.......
  77.  
  78.                 mov ebx,"YDOB"        ; search for bitmap-data
  79. x3:             mov eax,ds:[esi]
  80.                 cmp eax,ebx
  81.                 je x4
  82.  
  83.                 inc esi
  84.                 dec ecx
  85.                 jnz x3
  86.                 stc
  87.                 mov ax,02h
  88.                 ret
  89.  
  90. x4:             add esi,8
  91.                 mov ds:[Bitmap_Table],esi  ; store offset to bitmap-data
  92.                 
  93.                 xor ebx,ebx                ; byte-counter to zero
  94.  
  95. x5:             mov al,ds:[esi]            ; read packed bitmap-data
  96.                 mov ah,al
  97.                 cmp ebx,ds:[Bitmap_Bytes]  ; all bytes stored ??
  98.                 jae x9                     ; yes, then end  this shit...
  99.  
  100.                 and al,10000000b           ; check if equal or different bytes
  101.                 cmp al,80h                 ; to copy
  102.                 je x7                      ; if bit 7 set then equal bytes to
  103.                                            ; read
  104.                 
  105.                 mov cl,ah                  ; setup counter to copy bytes
  106.                 xor ch,ch
  107.                 inc cx
  108.                 inc esi
  109.  
  110. x6:             mov al,ds:[esi]            ; copy-routine for different bytes
  111.                 mov ds:[edi],al
  112.                 inc esi
  113.                 inc edi
  114.                 inc bx
  115.                 dec cx
  116.                 jnz x6
  117.  
  118.                 jmp x5
  119.  
  120. x7:             mov cl,ah                  ; setup counter to copy bytes
  121.                 xor ch,ch
  122.                 dec cx
  123.                 inc esi
  124.  
  125. x8:             mov al,ds:[esi]            ; copy-routine for equal bytes
  126.                 mov ds:[edi],al
  127.                 inc edi
  128.                 inc bx
  129.                 inc cx
  130.                 cmp cx,0100h
  131.                 jnz x8
  132.  
  133.                 inc esi
  134.                 jmp x5
  135.  
  136. x9:             mov ax,ds:[LBM_Xsize]
  137.                 mov bx,ds:[LBM_YSize]
  138.                 mov esi,ds:[Color_Table]
  139.                 clc
  140.                 ret                       ; end this shit......
  141.  
  142. ;════════════════════════════════════════════════════════════════════════════
  143.  
  144.